const router = require('koa-router')()
const model = require("../model");
let User = model.User; //获取User模型
router.prefix('/users')

router.get('/', function (ctx, next) {
  ctx.body = 'this is a users response!'
})

router.get('/bar2', function (ctx, next) {
  ctx.body = 'this is a users bar response'
})
/**
 * @swagger
 * /test/apps:
 *   get:
 *     summary: 获取有日志记录的应用
 *     description: 获取有日志记录的应用
 *     tags:
 *       - test
 *     parameters:
 *       - name: appName
 *         in: query
 *         required: true
 *         description: 应用名称
 *         type: string
 *       - name: userId
 *         in: query
 *         required: true
 *         description: 用户id
 *         type: string
 *     responses:
 *       200:
 *         description: 成功获取
 */
//查找所有
router.get('/allUser', async (ctx) => {
  try {
    let result = await User.findAll();
    if (result) {
      ctx.body = {
        code: 200,
        message: result
      }
    } else {
      ctx.body = {
        code: 500,
        message: '表中没有数据!',
      };
    }
  } catch (error) {
    ctx.body = {
      code: 500,
      message: '错误',
      data: err
    };
  }

})
module.exports = router
